<template>
	<view class="page-container">
		<!-- 资金总览区域 -->
		<view class="balance-section">
			<view class="balance-title">可用余额</view>
			<view class="balance-amount">¥ {{user.money}}</view>
		</view>

		<!-- 明细分类标签 -->
		<scroll-view class="filter-tabs" scroll-x>
			<view v-for="(tab, index) in tabs" :key="index" class="tab-item" :class="{ active: activeTab === tab.type }"
				@click="switchTab(tab.type)">
				{{ tab.name }}
			</view>
		</scroll-view>

		<!-- 记录列表 -->
		<view v-for="(record, index) in records" :key="index" class="record-item">
			<view class="record-icon">
				<uni-icons type="wallet" size="24"
					color="#07C160"></uni-icons>
			</view>
			<view class="record-content">
				<view class="record-title">{{ record.memo }}</view>
				<view class="record-time">{{ record.createtime }}</view>
			</view>
			<view class="record-amount" :style="{ color: record.memo != '后台扣除' ? '#07C160' : '#FF4D4F' }">
				{{ record.memo != '后台扣除' ? '+' : '-' }}¥{{ record.money }}
			</view>
		</view>

	</view>
</template>

<script>
	import {curl} from 'common/api.js';
	export default {
		data() {
			return {
				activeTab: 'all',
				currentBalance: '123',
				tabs: [{
						name: '全部',
						type: 'all'
					},
					{
						name: '收入',
						type: 'income'
					},
					{
						name: '支出',
						type: 'expense'
					},

				],
				records: [],
				user:[]
			}
		},
		
		onShow() {
			var that=this;
			curl('user/index', {}).then((res) => {
				console.log(res.data);
				that.user=res.data
			});
			
			this.getallmoneylog();
		},
		methods: {
			switchTab(ret){
				console.log(ret);
				
				this.activeTab=ret,
				this.records=[];
				this.getallmoneylog();
			},
			getallmoneylog(){
				var activeTab=this.activeTab;
				
				var that=this;
				curl('money/getallmoneylog', {activeTab:activeTab}).then((res) => {
					console.log(res.data);
					that.records=res.data
				});
			}
		}
	}
</script>

<style>
	page {
		height: 100%;
		background-color: #f7f7f7;
	}

	.page-container {
		display: flex;
		flex-direction: column;
		height: 100%;
		background-color: #f7f7f7;
	}

	/* 顶部标题栏样式 */
	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx 30rpx;
		background-color: #fff;
		position: relative;
		z-index: 10;
	}

	.header .title {
		font-size: 36rpx;
		font-weight: 600;
		color: #333;
	}

	.header .action {
		width: 40rpx;
		height: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	/* 资金总览区域样式 */
	.balance-section {
		background-color: #fff;
		padding: 40rpx 30rpx;
		margin-bottom: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.balance-title {
		font-size: 28rpx;
		color: #999;
		margin-bottom: 10rpx;
	}

	.balance-amount {
		font-size: 64rpx;
		font-weight: 600;
		color: #333;
		margin-bottom: 30rpx;
	}

	.balance-actions {
		display: flex;
		justify-content: center;
		gap: 30rpx;
		width: 100%;
	}

	.action-btn {
		flex: 1;
		max-width: 200rpx;
	}

	/* 筛选标签样式 */
	.filter-tabs {
		white-space: nowrap;
		background-color: #fff;
		padding: 20rpx 30rpx;
		margin-bottom: 20rpx;
	}

	.tab-item {
		display: inline-block;
		padding: 10rpx 30rpx;
		margin-right: 20rpx;
		font-size: 28rpx;
		color: #666;
		border-radius: 30rpx;
		background-color: #f5f5f5;
	}

	.tab-item.active {
		background-color: #1890ff;
		color: #fff;
	}

	/* 记录列表样式 */
	.record-list {
		flex: 1;
		background-color: #fff;
		padding: 0 30rpx;
	}

	.empty-state {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 100rpx 0;
	}

	.empty-image {
		width: 300rpx;
		height: 300rpx;
		margin-bottom: 30rpx;
	}

	.empty-text {
		font-size: 28rpx;
		color: #999;
	}

	.record-item {
		display: flex;
		align-items: center;
		width: 680rpx;margin: 15rpx auto;
		background: #ffffff;
		padding: 30rpx 20rpx;
		border-bottom: 1px solid #f0f0f0;
	}

	.record-item:last-child {
		border-bottom: none;
	}

	.record-icon {
		width: 48rpx;
		height: 48rpx;
		margin-right: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.record-content {
		flex: 1;
	}

	.record-title {
		font-size: 30rpx;
		color: #333;
		margin-bottom: 8rpx;
	}

	.record-time {
		font-size: 24rpx;
		color: #999;
	}

	.record-amount {
		font-size: 32rpx;
		font-weight: 600;
	}

	.loading-more {
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 30rpx 0;
		font-size: 24rpx;
		color: #999;
	}

	.loading-more text {
		margin-left: 10rpx;
	}

	/* 筛选弹窗样式 */
	.filter-popup {
		background-color: #fff;
		border-radius: 16rpx 16rpx 0 0;
		padding: 30rpx;
	}

	.popup-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.popup-title {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
	}

	.popup-content {
		margin-bottom: 40rpx;
	}

	.filter-option {
		margin-bottom: 30rpx;
	}

	.filter-option text {
		display: block;
		font-size: 28rpx;
		color: #666;
		margin-bottom: 15rpx;
	}

	.picker {
		padding: 20rpx;
		background-color: #f5f5f5;
		border-radius: 8rpx;
		font-size: 28rpx;
		color: #333;
	}

	.amount-range {
		display: flex;
		align-items: center;
	}

	.amount-input {
		flex: 1;
		padding: 20rpx;
		background-color: #f5f5f5;
		border-radius: 8rpx;
		font-size: 28rpx;
		color: #333;
		text-align: center;
	}

	.amount-range text {
		margin: 0 20rpx;
		font-size: 28rpx;
		color: #666;
	}

	.popup-footer {
		display: flex;
		justify-content: space-between;
	}

	.popup-footer button {
		flex: 1;
		margin: 0 15rpx;
	}
</style>